package tree;

import javax.swing.tree.*;
import java.util.*;

public class TreeFactory {
	public static void addNodes(DefaultTreeModel model, AbstractTreeNode parent, List list) {
		if (null == list || 0 == list.size())
			return;

		int i = 0;
		AbstractTreeNode node = null;
		parent.removeAllChildren();
		ListIterator itor = list.listIterator();
		switch (parent.getNodeType()) {
		case AbstractTreeNode.RootNode:
			while (itor.hasNext()) {
				node = new CatalogNode(itor.next());
				model.insertNodeInto(node, parent, i++);
			}
			break;
		case AbstractTreeNode.CatalogNode:
			while (itor.hasNext()) {
				node = new TableNode(itor.next());
				model.insertNodeInto(node, parent, i++);
			}
			break;
		case AbstractTreeNode.TableNode:
			while (itor.hasNext()) {
				node = new FieldNode(itor.next());
				model.insertNodeInto(node, parent, i++);
			}
			break;
		case AbstractTreeNode.FieldNode:
			System.out.println("TreeFactory.addNodes(..)�������:" + "FieldNodeֻ����Ҷ��");
			return;
		default:
			System.out.println("TreeFactory.addNodes(..)�������:" + "�����node����");
			return;
		}
		model.reload(parent);
	}
}
